from django.conf import settings
from django import template

register = template.Library()

  
@register.filter("swear")
def replace_bad_words(value):
    """ Replaces profanities in strings with safe words
    For instance, "shit" becomes "s--t"
    """
    words_seen = [w for w in settings.PROFANITIES_LIST if w in value]
    if words_seen:
      for word in words_seen:
        value = value.replace(word, "%s%s%s" % (word[0], '-'*(len(word)-2), word[-1]))
    return value
